import { View } from "../../../mvc/core/View";
import { LayerManager } from "../../manager/LayerManager";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { EventName } from "../../mvc/EventName";
import { DataEvent } from "../../events/DataEvent";
import { Global } from "../../../../com/gengine/global/Global";
import { SecTimer } from "../../../../com/gengine/core/frame/SecTimer";
import { TimerType } from "../../../../com/gengine/core/frame/TimerType";
import { AttachedSoulBattlefielAidPlayer } from "./AttachedSoulBattlefielAidPlayer";
import { TowerInfoHideButton } from "../copy/magicTower/TowerInfoHideButton";
import { ImagesConst } from "../../resource/ImagesConst";
import { TweenMax } from "../../../../com/greensock/TweenMax";
import { Quint } from "../../../../com/greensock/easing/Quint";
import { SEntityId } from "../../../../Message/Public/SEntityId";
import { SPublicMiniPlayer } from "../../../../Message/Public/SPublicMiniPlayer";
import { EntityUtil } from "../../scene/layer/utils/EntityUtil";
import { ThingUtil } from "../../scene/layer/utils/ThingUtil";
import { UserPlayer } from "../../scene/player/entity/UserPlayer";
import { SpritePlayer } from "../../scene/player/entity/SpritePlayer";
import { GButton } from "../../../../com/mui/controls/GButton";
type int = number;
//class AttachedSoulBattlefielAids
    
    export  class AttachedSoulBattlefielAids extends View
    {
        constructor(arg1: int=5)
        {
            super();
            this._aryEnemy = [];
            this._aidPlayerArray = [];
            this.layer = LayerManager.uiLayer;
            this._aidPlayerLen = arg1;
            this.init();
            this.resetPosition();
            Dispatcher.addEventListener(EventName.StageResize, this.onStageResize);
            return;
        }

        /* internal  */onStageResize(arg1: DataEvent): void
        {
            this.resetPosition();
            return;
        }

        /* internal  */resetPosition(): void
        {
            this.y = 195;
            this.x = Global.stage.stageWidth - 225;
            return;
        }

        /* internal  */init(): void
        {
            var loc1=null;
            if (!this._timer) 
            {
                this._timer = new SecTimer(1);
                this._timer.addListener(TimerType.ENTERFRAME, this.onEnterFrame);
            }
            var loc2=0;
            while (loc2 < this._aidPlayerLen) 
            {
                loc1 = new AttachedSoulBattlefielAidPlayer();
                loc1.buttonMode = true;
                this._aidPlayerArray.push(loc1);
                ++loc2;
            }
            this._zoomBtn = new TowerInfoHideButton(ImagesConst.GangFightsEnemyInfoBg);
            this._zoomBtn.x = 210;
            this._zoomBtn.y = 9;
            this.addChild(this._zoomBtn);
            this._zoomBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onZoomBtnClick);
            this._contentSp = new Object /* flash.display.Sprite */();
            this.addChild(this._contentSp);
            return;
        }

        /* internal  */onZoomBtnClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._zoomBtn.show) 
            {
                this.hidePanel();
            }
            else 
            {
                this.showPanel();
            }
            return;
        }

        public isBbserveView(): void
        {
            this.x = 0;
            this.y = 160;
            this._zoomBtn.visible = false;
            Dispatcher.removeEventListener(EventName.StageResize, this.onStageResize);
            return;
        }

        public hidePanel(): void
        {
            if (this._showTween && this._showTween.active) 
            {
                this._showTween.kill();
            }
            this._hideTween = TweenMax.to(this._contentSp, 0.2, {"x": 225, "ease": Quint.easeOut, "onComplete": this.onHideEnd});
            this._zoomBtn.show = false;
            return;
        }

        /* internal  */onHideEnd(): void
        {
            if (this._contentSp.parent) 
            {
                removeChild(this._contentSp);
            }
            return;
        }

        public showPanel(): void
        {
            if (this._hideTween && this._hideTween.active) 
            {
                this._hideTween.kill();
            }
            this._showTween = TweenMax.to(this._contentSp, 0.2, {"x": 0, "ease": Quint.easeIn});
            this._zoomBtn.show = true;
            if (!this._contentSp.parent) 
            {
                addChild(this._contentSp);
            }
            return;
        }

        public setEnemys(arg1: Array<any>): void
        {
            var loc2=null;
            this.clear();
            this._aryEnemy = arg1;
            var loc1=0;
            while (loc1 < this._aryEnemy.length) 
            {
                loc2 = this._aidPlayerArray[loc1] as AttachedSoulBattlefielAidPlayer;
                loc2.miniPlayer = arg1[loc1];
                loc2.y = 68 * loc1;
                this._contentSp.addChild(loc2);
                ++loc1;
            }
            return;
        }

        /* internal  */clear(): void
        {
            var loc2=null;
            var loc1=0;
            while (loc1 < this._aidPlayerArray.length) 
            {
                loc2 = this._aidPlayerArray[loc1] as AttachedSoulBattlefielAidPlayer;
                if (loc2 && loc2.parent) 
                {
                    loc2.parent.removeChild(loc2);
                    loc2.dispose();
                }
                ++loc1;
            }
            return;
        }

        public setDead(arg1: SEntityId): void
        {
            var loc2=null;
            var loc1=0;
            while (loc1 < this._aryEnemy.length) 
            {
                loc2 = this._aryEnemy[loc1] as SPublicMiniPlayer;
                if (EntityUtil.equal(loc2.entityId, arg1)) 
                {
                    (this._aidPlayerArray[loc1] as AttachedSoulBattlefielAidPlayer).setDead();
                }
                ++loc1;
            }
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            this._timer.stop();
            Dispatcher.removeEventListener(EventName.Player_Selected, this.onPlayerSelected);
            this.clear();
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            this._timer.start();
            Dispatcher.addEventListener(EventName.Player_Selected, this.onPlayerSelected);
            return;
        }

        /* internal  */onEnterFrame(arg1: SecTimer): void
        {
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc5=null;
            var loc1=0;
            while (loc1 < this._aryEnemy.length) 
            {
                loc2 = this._aryEnemy[loc1] as SPublicMiniPlayer;
                if (loc3 = ThingUtil.entityUtil.getEntity(loc2.entityId) as UserPlayer) 
                {
                    loc4 = loc3.getSelfPet();
                    loc5 = this._aidPlayerArray[loc1];
                }
                ++loc1;
            }
            return;
        }

        /* internal  */onPlayerSelected(arg1: DataEvent): void
        {
            var loc2=null;
            var loc1=arg1.data as SpritePlayer;
            if (!loc1) 
            {
                return;
            }
            var loc3=0;
            while (loc3 < this._aryEnemy.length) 
            {
                loc2 = this._aidPlayerArray[loc3] as AttachedSoulBattlefielAidPlayer;
                if (loc2.isSelfEntity(loc1.entityID)) 
                {
                    if (typeof loc1 === "userplayer") 
                    {
                        loc2.select = true;
                    }
                }
                else 
                {
                    loc2.select = false;
                }
                ++loc3;
            }
            return;
        }

        /* internal */ /* var */_timer: SecTimer;

        /* internal */ /* var */_aryEnemy: Array<any>;

        /* internal */ /* var */_aidPlayerArray: Array<any>;

        /* internal */ /* var */_zoomBtn: TowerInfoHideButton;

        /* internal */ /* var */_contentSp: Object /* flash.display.Sprite */;

        /* internal */ /* var */_moveBtn: GButton;

        /* internal */ /* var */_aidPlayerLen: int;

        /* internal */ /* var */_hideTween: TweenMax;

        /* internal */ /* var */_showTween: TweenMax;
    }
